package com.easymin.weixin.filters;

import com.easymin.weixin.common.IpHelper;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CodeFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {

        try {
            String[] str = new String[]{"v5/passenger/sendvcodev2",
                    "h5/checkBind",
                    "h5/sendVCode",
                    "h5/v3/checkBind",
                    "h5/v3/sendVCode",
                    "h5/v4/checkBind",
                    "h5/v4/sendVCode"};
            for (String s : str) {
                if (httpServletRequest.getRequestURL().toString().contains(s) || httpServletRequest.getRequestURI().toString().contains(s)) {
                    System.out.println(IpHelper.getIp(httpServletRequest));
                    break;
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }
}
